<?php


abstract class BaseTong extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $scene_id;


	
	protected $name;


	
	protected $img;


	
	protected $head_user_id;


	
	protected $head_user_id2;


	
	protected $members;


	
	protected $des;


	
	protected $status;


	
	protected $join_type;


	
	protected $tong_type;


	
	protected $integral;


	
	protected $created_at;


	
	protected $updated_at;

	
	protected $aScene;

	
	protected $aUcMembers;

	
	protected $collTongMembers;

	
	protected $lastTongMemberCriteria = null;

	
	protected $collTongTopics;

	
	protected $lastTongTopicCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getSceneId()
	{

		return $this->scene_id;
	}

	
	public function getName()
	{

		return $this->name;
	}

	
	public function getImg()
	{

		return $this->img;
	}

	
	public function getHeadUserId()
	{

		return $this->head_user_id;
	}

	
	public function getHeadUserId2()
	{

		return $this->head_user_id2;
	}

	
	public function getMembers()
	{

		return $this->members;
	}

	
	public function getDes()
	{

		return $this->des;
	}

	
	public function getStatus()
	{

		return $this->status;
	}

	
	public function getJoinType()
	{

		return $this->join_type;
	}

	
	public function getTongType()
	{

		return $this->tong_type;
	}

	
	public function getIntegral()
	{

		return $this->integral;
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = TongPeer::ID;
		}

	} 
	
	public function setSceneId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->scene_id !== $v) {
			$this->scene_id = $v;
			$this->modifiedColumns[] = TongPeer::SCENE_ID;
		}

		if ($this->aScene !== null && $this->aScene->getId() !== $v) {
			$this->aScene = null;
		}

	} 
	
	public function setName($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->name !== $v) {
			$this->name = $v;
			$this->modifiedColumns[] = TongPeer::NAME;
		}

	} 
	
	public function setImg($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->img !== $v) {
			$this->img = $v;
			$this->modifiedColumns[] = TongPeer::IMG;
		}

	} 
	
	public function setHeadUserId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->head_user_id !== $v) {
			$this->head_user_id = $v;
			$this->modifiedColumns[] = TongPeer::HEAD_USER_ID;
		}

		if ($this->aUcMembers !== null && $this->aUcMembers->getUid() !== $v) {
			$this->aUcMembers = null;
		}

	} 
	
	public function setHeadUserId2($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->head_user_id2 !== $v) {
			$this->head_user_id2 = $v;
			$this->modifiedColumns[] = TongPeer::HEAD_USER_ID2;
		}

	} 
	
	public function setMembers($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->members !== $v) {
			$this->members = $v;
			$this->modifiedColumns[] = TongPeer::MEMBERS;
		}

	} 
	
	public function setDes($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->des !== $v) {
			$this->des = $v;
			$this->modifiedColumns[] = TongPeer::DES;
		}

	} 
	
	public function setStatus($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->status !== $v) {
			$this->status = $v;
			$this->modifiedColumns[] = TongPeer::STATUS;
		}

	} 
	
	public function setJoinType($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->join_type !== $v) {
			$this->join_type = $v;
			$this->modifiedColumns[] = TongPeer::JOIN_TYPE;
		}

	} 
	
	public function setTongType($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->tong_type !== $v) {
			$this->tong_type = $v;
			$this->modifiedColumns[] = TongPeer::TONG_TYPE;
		}

	} 
	
	public function setIntegral($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->integral !== $v) {
			$this->integral = $v;
			$this->modifiedColumns[] = TongPeer::INTEGRAL;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = TongPeer::CREATED_AT;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = TongPeer::UPDATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->scene_id = $rs->getInt($startcol + 1);

			$this->name = $rs->getString($startcol + 2);

			$this->img = $rs->getString($startcol + 3);

			$this->head_user_id = $rs->getInt($startcol + 4);

			$this->head_user_id2 = $rs->getInt($startcol + 5);

			$this->members = $rs->getString($startcol + 6);

			$this->des = $rs->getString($startcol + 7);

			$this->status = $rs->getString($startcol + 8);

			$this->join_type = $rs->getString($startcol + 9);

			$this->tong_type = $rs->getString($startcol + 10);

			$this->integral = $rs->getInt($startcol + 11);

			$this->created_at = $rs->getTimestamp($startcol + 12, null);

			$this->updated_at = $rs->getTimestamp($startcol + 13, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 14; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Tong object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TongPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TongPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isNew() && !$this->isColumnModified(TongPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

    if ($this->isModified() && !$this->isColumnModified(TongPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TongPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aScene !== null) {
				if ($this->aScene->isModified()) {
					$affectedRows += $this->aScene->save($con);
				}
				$this->setScene($this->aScene);
			}

			if ($this->aUcMembers !== null) {
				if ($this->aUcMembers->isModified()) {
					$affectedRows += $this->aUcMembers->save($con);
				}
				$this->setUcMembers($this->aUcMembers);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TongPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TongPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collTongMembers !== null) {
				foreach($this->collTongMembers as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collTongTopics !== null) {
				foreach($this->collTongTopics as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aScene !== null) {
				if (!$this->aScene->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aScene->getValidationFailures());
				}
			}

			if ($this->aUcMembers !== null) {
				if (!$this->aUcMembers->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUcMembers->getValidationFailures());
				}
			}


			if (($retval = TongPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collTongMembers !== null) {
					foreach($this->collTongMembers as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collTongTopics !== null) {
					foreach($this->collTongTopics as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TongPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getSceneId();
				break;
			case 2:
				return $this->getName();
				break;
			case 3:
				return $this->getImg();
				break;
			case 4:
				return $this->getHeadUserId();
				break;
			case 5:
				return $this->getHeadUserId2();
				break;
			case 6:
				return $this->getMembers();
				break;
			case 7:
				return $this->getDes();
				break;
			case 8:
				return $this->getStatus();
				break;
			case 9:
				return $this->getJoinType();
				break;
			case 10:
				return $this->getTongType();
				break;
			case 11:
				return $this->getIntegral();
				break;
			case 12:
				return $this->getCreatedAt();
				break;
			case 13:
				return $this->getUpdatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TongPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getSceneId(),
			$keys[2] => $this->getName(),
			$keys[3] => $this->getImg(),
			$keys[4] => $this->getHeadUserId(),
			$keys[5] => $this->getHeadUserId2(),
			$keys[6] => $this->getMembers(),
			$keys[7] => $this->getDes(),
			$keys[8] => $this->getStatus(),
			$keys[9] => $this->getJoinType(),
			$keys[10] => $this->getTongType(),
			$keys[11] => $this->getIntegral(),
			$keys[12] => $this->getCreatedAt(),
			$keys[13] => $this->getUpdatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TongPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setSceneId($value);
				break;
			case 2:
				$this->setName($value);
				break;
			case 3:
				$this->setImg($value);
				break;
			case 4:
				$this->setHeadUserId($value);
				break;
			case 5:
				$this->setHeadUserId2($value);
				break;
			case 6:
				$this->setMembers($value);
				break;
			case 7:
				$this->setDes($value);
				break;
			case 8:
				$this->setStatus($value);
				break;
			case 9:
				$this->setJoinType($value);
				break;
			case 10:
				$this->setTongType($value);
				break;
			case 11:
				$this->setIntegral($value);
				break;
			case 12:
				$this->setCreatedAt($value);
				break;
			case 13:
				$this->setUpdatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TongPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setSceneId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setName($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setImg($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setHeadUserId($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setHeadUserId2($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setMembers($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setDes($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setStatus($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setJoinType($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setTongType($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setIntegral($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setUpdatedAt($arr[$keys[13]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TongPeer::DATABASE_NAME);

		if ($this->isColumnModified(TongPeer::ID)) $criteria->add(TongPeer::ID, $this->id);
		if ($this->isColumnModified(TongPeer::SCENE_ID)) $criteria->add(TongPeer::SCENE_ID, $this->scene_id);
		if ($this->isColumnModified(TongPeer::NAME)) $criteria->add(TongPeer::NAME, $this->name);
		if ($this->isColumnModified(TongPeer::IMG)) $criteria->add(TongPeer::IMG, $this->img);
		if ($this->isColumnModified(TongPeer::HEAD_USER_ID)) $criteria->add(TongPeer::HEAD_USER_ID, $this->head_user_id);
		if ($this->isColumnModified(TongPeer::HEAD_USER_ID2)) $criteria->add(TongPeer::HEAD_USER_ID2, $this->head_user_id2);
		if ($this->isColumnModified(TongPeer::MEMBERS)) $criteria->add(TongPeer::MEMBERS, $this->members);
		if ($this->isColumnModified(TongPeer::DES)) $criteria->add(TongPeer::DES, $this->des);
		if ($this->isColumnModified(TongPeer::STATUS)) $criteria->add(TongPeer::STATUS, $this->status);
		if ($this->isColumnModified(TongPeer::JOIN_TYPE)) $criteria->add(TongPeer::JOIN_TYPE, $this->join_type);
		if ($this->isColumnModified(TongPeer::TONG_TYPE)) $criteria->add(TongPeer::TONG_TYPE, $this->tong_type);
		if ($this->isColumnModified(TongPeer::INTEGRAL)) $criteria->add(TongPeer::INTEGRAL, $this->integral);
		if ($this->isColumnModified(TongPeer::CREATED_AT)) $criteria->add(TongPeer::CREATED_AT, $this->created_at);
		if ($this->isColumnModified(TongPeer::UPDATED_AT)) $criteria->add(TongPeer::UPDATED_AT, $this->updated_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TongPeer::DATABASE_NAME);

		$criteria->add(TongPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setSceneId($this->scene_id);

		$copyObj->setName($this->name);

		$copyObj->setImg($this->img);

		$copyObj->setHeadUserId($this->head_user_id);

		$copyObj->setHeadUserId2($this->head_user_id2);

		$copyObj->setMembers($this->members);

		$copyObj->setDes($this->des);

		$copyObj->setStatus($this->status);

		$copyObj->setJoinType($this->join_type);

		$copyObj->setTongType($this->tong_type);

		$copyObj->setIntegral($this->integral);

		$copyObj->setCreatedAt($this->created_at);

		$copyObj->setUpdatedAt($this->updated_at);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getTongMembers() as $relObj) {
				$copyObj->addTongMember($relObj->copy($deepCopy));
			}

			foreach($this->getTongTopics() as $relObj) {
				$copyObj->addTongTopic($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TongPeer();
		}
		return self::$peer;
	}

	
	public function setScene($v)
	{


		if ($v === null) {
			$this->setSceneId(NULL);
		} else {
			$this->setSceneId($v->getId());
		}


		$this->aScene = $v;
	}


	
	public function getScene($con = null)
	{
		if ($this->aScene === null && ($this->scene_id !== null)) {
						include_once 'lib/model/om/BaseScenePeer.php';

			$this->aScene = ScenePeer::retrieveByPK($this->scene_id, $con);

			
		}
		return $this->aScene;
	}

	
	public function setUcMembers($v)
	{


		if ($v === null) {
			$this->setHeadUserId(NULL);
		} else {
			$this->setHeadUserId($v->getUid());
		}


		$this->aUcMembers = $v;
	}


	
	public function getUcMembers($con = null)
	{
		if ($this->aUcMembers === null && ($this->head_user_id !== null)) {
						include_once 'lib/model/om/BaseUcMembersPeer.php';

			$this->aUcMembers = UcMembersPeer::retrieveByPK($this->head_user_id, $con);

			
		}
		return $this->aUcMembers;
	}

	
	public function initTongMembers()
	{
		if ($this->collTongMembers === null) {
			$this->collTongMembers = array();
		}
	}

	
	public function getTongMembers($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTongMemberPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTongMembers === null) {
			if ($this->isNew()) {
			   $this->collTongMembers = array();
			} else {

				$criteria->add(TongMemberPeer::TONG_ID, $this->getId());

				TongMemberPeer::addSelectColumns($criteria);
				$this->collTongMembers = TongMemberPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TongMemberPeer::TONG_ID, $this->getId());

				TongMemberPeer::addSelectColumns($criteria);
				if (!isset($this->lastTongMemberCriteria) || !$this->lastTongMemberCriteria->equals($criteria)) {
					$this->collTongMembers = TongMemberPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTongMemberCriteria = $criteria;
		return $this->collTongMembers;
	}

	
	public function countTongMembers($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseTongMemberPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(TongMemberPeer::TONG_ID, $this->getId());

		return TongMemberPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addTongMember(TongMember $l)
	{
		$this->collTongMembers[] = $l;
		$l->setTong($this);
	}


	
	public function getTongMembersJoinUcMembers($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTongMemberPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTongMembers === null) {
			if ($this->isNew()) {
				$this->collTongMembers = array();
			} else {

				$criteria->add(TongMemberPeer::TONG_ID, $this->getId());

				$this->collTongMembers = TongMemberPeer::doSelectJoinUcMembers($criteria, $con);
			}
		} else {
									
			$criteria->add(TongMemberPeer::TONG_ID, $this->getId());

			if (!isset($this->lastTongMemberCriteria) || !$this->lastTongMemberCriteria->equals($criteria)) {
				$this->collTongMembers = TongMemberPeer::doSelectJoinUcMembers($criteria, $con);
			}
		}
		$this->lastTongMemberCriteria = $criteria;

		return $this->collTongMembers;
	}

	
	public function initTongTopics()
	{
		if ($this->collTongTopics === null) {
			$this->collTongTopics = array();
		}
	}

	
	public function getTongTopics($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTongTopicPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTongTopics === null) {
			if ($this->isNew()) {
			   $this->collTongTopics = array();
			} else {

				$criteria->add(TongTopicPeer::TONG_ID, $this->getId());

				TongTopicPeer::addSelectColumns($criteria);
				$this->collTongTopics = TongTopicPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TongTopicPeer::TONG_ID, $this->getId());

				TongTopicPeer::addSelectColumns($criteria);
				if (!isset($this->lastTongTopicCriteria) || !$this->lastTongTopicCriteria->equals($criteria)) {
					$this->collTongTopics = TongTopicPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTongTopicCriteria = $criteria;
		return $this->collTongTopics;
	}

	
	public function countTongTopics($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseTongTopicPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(TongTopicPeer::TONG_ID, $this->getId());

		return TongTopicPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addTongTopic(TongTopic $l)
	{
		$this->collTongTopics[] = $l;
		$l->setTong($this);
	}


	
	public function getTongTopicsJoinUcMembers($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTongTopicPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTongTopics === null) {
			if ($this->isNew()) {
				$this->collTongTopics = array();
			} else {

				$criteria->add(TongTopicPeer::TONG_ID, $this->getId());

				$this->collTongTopics = TongTopicPeer::doSelectJoinUcMembers($criteria, $con);
			}
		} else {
									
			$criteria->add(TongTopicPeer::TONG_ID, $this->getId());

			if (!isset($this->lastTongTopicCriteria) || !$this->lastTongTopicCriteria->equals($criteria)) {
				$this->collTongTopics = TongTopicPeer::doSelectJoinUcMembers($criteria, $con);
			}
		}
		$this->lastTongTopicCriteria = $criteria;

		return $this->collTongTopics;
	}

} 